from fastapi import APIRouter
from ..domain import QuestionGenerateRequest
from ..internal.question_ganerate_utils import QuestionGanerateUtils
from ..internal.file_update_utils import FileUpdateUtils
from fastapi.responses import StreamingResponse
from typing import Annotated, List
from fastapi import FastAPI, UploadFile, File, Form, HTTPException, status
from fastapi import FastAPI, Request, HTTPException



# 初始化 FastAPI 应用
router = APIRouter()


@router.post("/api/questionGenerate/generate")
async def questionGenerate(request: QuestionGenerateRequest):
    try:
        print(request)
        questionGanerateUtils = QuestionGanerateUtils(request)
        return await questionGanerateUtils.question()
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e))

@router.post("/api/questionGenerate/fileUpload")
async def upload_file(
    session_id: Annotated[str, Form(..., description="用户会话ID")],
    files: Annotated[List[UploadFile], File(..., description="上传文件列表")]
):
    try:
        print(session_id,files)
        fuu = FileUpdateUtils(session_id,files)
        return await fuu.update()
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e))